package com.yst.metho.web.application.pointage;

import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;

import nextapp.echo2.app.table.AbstractTableModel;
import nextapp.echo2.app.table.TableModel;

import com.yst.suivi.data.pointage.Pointage;
import com.yst.suivi.util.Constants;

public class MyActivityModel extends AbstractTableModel implements TableModel
{
	private String[] mColumnsName =

	{ "", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" };

	private String[] mTitle =
	{ "8h-10", "10h-12h", "14h-16h", "16h-18h" };

	// 7 a cause de la premiere
	// colonne qui represente la division du temps dans la journee
	private Object[][] mPointages = new Object[7][Constants.DAY_SUBDIVISION]; // 

	public MyActivityModel()
	{
		for (int i = 0; i < Constants.DAY_SUBDIVISION; i++)
		{
			mPointages[0][i] = mTitle[i];
		}
	}

	public void addDay(Collection pointage, Calendar day)
	{
		Iterator it = pointage.iterator();
		Pointage pointageItem;
		int index = 0;
		while (it.hasNext())
		{
			pointageItem = (Pointage) it.next();
			for (int i = 0; i < pointageItem.getTempsPos().intValue(); i++)
			{
				mPointages[(day.get(Calendar.DAY_OF_WEEK) - Calendar.MONDAY) + 1][index] = pointageItem;
				index++;
			}
		}
	}

	public int getRowCount()
	{
		return Constants.DAY_SUBDIVISION;
	}

	public Object getValueAt(int column, int row)
	{
		// Collection col = mPointages[column];
		// Object retour = null;
		// if (null != col)
		// {
		//
		// if (row < col.size())
		// {
		// Iterator it = col.iterator();
		// for (int i = 0; i <= row; i++)
		// {
		// retour = it.next();
		// }
		// }
		// }
		return mPointages[column][row];
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.AbstractTableModel#getColumnName(int)
	 */
	public String getColumnName(int arg0)
	{
		return mColumnsName[arg0];
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.TableModel#getColumnCount()
	 */
	public int getColumnCount()
	{
		return mColumnsName.length;
	}

}
